<?php

namespace app\admin\controller;

class Life extends Base
{
    //游学体验列表
    public function life()
    {
        $life = model('common/Life')
            -> order('create_time','desc')
            -> paginate(8);
        $data = ['life' => $life];
        $this -> assign($data);
        return view();
    }

    //游学体验添加
    public function life_add()
    {
        if (request()->isAjax()){
            $data = input('post.');
            $data['img'] = request() -> file('myFile');
            $result = model('common/Life') -> life_add($data);
            if ($result == 1){
                $this -> success('添加成功！','admin/life/life');
            } else {
                $this -> error($result);
            }
        }
        return view();
    }

    //游学体验编辑
    public function life_edit()
    {
        if (request()->isAjax()){
            $data = input('post.');
            $data['imgs'] = request()->file('myFile');
            $result = model('common/Life') -> life_edit($data);
            if ($result == 1){
                $this -> success('更新成功！','admin/life/life');
            } else {
                $this -> error($result);
            }
        }
        $life = model('common/Life') -> find(input('id'));
        $data = [
            'life' => $life
        ];
        $this -> assign($data);
        return view();
    }

    //游学体验删除
    public function life_del()
    {
        if (request()->isAjax()){
            $life = model('common/Life') -> find(input('id'));
            $result = $life -> delete();
            if ($result){
                $this -> success('删除成功！','admin/life/life');
            } else {
                $this -> error('删除失败！');
            }
        } else {
            return '非法请求';
        }
    }

    //游学体验简介
    public function lifes()
    {
        if (request()->isAjax()){
            $data = input('post.');
            $result = model('common/Classify') -> lifes($data);
            if ($result == 1){
                $this -> success('更新成功！','admin/life/lifes');
            } else {
                $this -> error($result);
            }
        }
        $cla = model('common/Classify') -> find();
        $data = ['cla' => $cla];
        $this ->assign($data);
        return view();
    }

}
